//
//  MyPresentationController.swift
//  weibo
//
//  Created by 叶子韬韬 on 2017/4/22.
//  Copyright © 2017年 叶子韬韬. All rights reserved.
//

import UIKit

class MyPresentationController: UIPresentationController {
    
    // MARK:- #注释> 对外提供属性
    var presentedFram:CGRect = CGRect.zero
    

    // MARK:- #注释> 懒加载属性
    internal lazy var coverView:UIView = UIView()
    
    override func containerViewWillLayoutSubviews() {
        super.containerViewWillLayoutSubviews()
        
        // 设置弹出view的尺寸
        presentedView?.frame = presentedFram
        
        // 添加蒙版
        setupCoverView()
    }
}

extension MyPresentationController{
    
    internal func setupCoverView(){
        // 添加蒙版
        containerView?.insertSubview(coverView, at: 0)
        
        //设置背景颜色
        coverView.backgroundColor = UIColor(white: 0.8, alpha: 0.2)
        coverView.frame = containerView!.bounds
        
        
        //添加手势
        let tapGes = UITapGestureRecognizer(target: self, action: #selector(MyPresentationController.coverViewClick))
        coverView.addGestureRecognizer(tapGes)
        
        
    }
}
// MARK:- #注释>监听事件
extension MyPresentationController{
    internal func coverViewClick(){
        presentedViewController.dismiss(animated: true, completion: nil)
    }
}
